import os
from functools import lru_cache

from pydantic import BaseConfig as Base

ROOT_PATH = os.path.abspath(os.curdir)


class BaseSettings(Base):
    """配置基类"""

    class Config:
        env_file_encoding = 'utf-8'


class Settings(BaseSettings):
    """
    应用基础信息配置
    """
    debug: bool = False
    title: str = "fastapi-template"
    description: str = "api接口页面"
    version: str = "1.0.0"
    """
    数据库配置
    """
    # 数据库地址
    database_url: str = '127.0.0.1'
    # 数据库端口
    database_port: int = 3306
    # 数据库用户名
    database_user: str = 'root'
    # 数据库密码
    database_password: str = '123456'
    # 数据库名
    database_name: str = 'db'


@lru_cache()
def get_settings() -> Settings:
    """获取并缓存应用配置"""
    return Settings()
